package com.ysc.BillArrange;

import com.ysc.IUDS.Class_Information;
import com.ysc.IUDS.Teacher_Information;
import com.ysc.domain.Bill;
import com.ysc.utils.mybatisUtils;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.session.SqlSession;

import java.util.Scanner;

public class PayFee {
    public static void PayFee(int money){
        Scanner in = new Scanner(System.in);
        SqlSession sqlSession = mybatisUtils.getSqlSession();

        System.out.println("输入您的个人信息（学号，课堂号，缴费时间）：");
        Bill bill = new Bill();
        bill.setStid(in.nextInt());
        int cid = in.nextInt();
        bill.setCid(cid);
        bill.setBtime(in.next());
        bill.setBill_Account(money);
        Class_Information class_information = new Class_Information();
        int tid = class_information.GetTidByCid(cid);
        Teacher_Information teacher_information = new Teacher_Information();
        int price = teacher_information.GetOncePrice(tid);
        bill.setLastClassNum(money/price);

        String SQLID = "com.ysc.Dao.BillDao.JudgeIfExist";
        int n = sqlSession.selectOne(SQLID,bill);
        System.out.println(n);
        if (n == 0){
            class_information.UpdateCNum(cid);
            sqlSession.commit();
        }

        SQLID = "com.ysc.Dao.BillDao.insertBill";
        sqlSession.insert(SQLID,bill);
        sqlSession.commit();

        SQLID = "com.ysc.Dao.BillDao.selectBill";
        sqlSession.selectOne(SQLID,bill);
        sqlSession.close();
    }
}
